package com.yzd.learnjava.strings;

import java.util.Scanner;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;

import com.yzd.learnjava.util.Print;
/*
 * Scanner
 */
public class ThreatAnalyzer {

	static String threatData = "58.27.82.176@02/10/2005\n"
			+ "204.45.234.40@02/11/2005\n"
			+ "58.27.82.176@02/11/2005\n"
			+ "58.27.82.176@02/11/2005\n"
			+ "58.27.82.176@02/11/2005\n"
			+ "[Next log section with different dada format]";
	public static void main(String[] args) {
		Scanner scanner = new Scanner(threatData);
		String pattern = "(\\d+[.]\\d+[.]\\d+[.]\\d+)@(\\d{2}/\\d{2}/\\d{4})";
		while(scanner.hasNext(pattern)) {
			scanner.next(pattern);
			MatchResult ma = scanner.match();
			String ip = ma.group(1);
			String date = ma.group(2);
			System.out.format("Threat on %s form %s\n", date, ip);
		}
	}

}
